package utils

import org.apache.commons.lang.StringUtils


/**
  * Created by 王康 on 2018/6/29.
  *   利用隐式转换  将String (包含空串) 转成 Int
  */
class RichString(val str:String){

  def parseInt= {
    try {
      if (StringUtils.isNotEmpty(str)) str.toInt else 0
    } catch {
      case _: Exception => 0
    }
  }

  def parseDouble= {
    try {
      if (StringUtils.isNotEmpty(str)) str.toDouble else 0.0
    } catch {
      case _: Exception => 0.0
    }
  }

}

object RichString{
  //导入隐式转换
  implicit def String2RichString(str:String) =new RichString(str)
}
